const exec = require("child_process").execSync;
const iconv = require("iconv-lite");
var ssidStr = run("netsh wlan show profile");
var ssids = ssidStr.split("\r\n    所有用户配置文件 : ");
ssids.shift(); // 删除顶端一行数据
ssids[ssids.length - 1] = ssids[ssids.length - 1].replace("\r\n\r\n", "");
for (var ssid of ssids) {
  const pswdStr = run(`netsh wlan show profile name="${ssid}" key=clear`);
  const matched = pswdStr.match(/关键内容            : (.*)\r\n/)
  const pswd = (matched === null ? '无密码' : matched[1])
  console.log(`${ssid}\t${pswd}`)
}

function run(cmd) {
  return iconv.decode(exec(cmd), "gbk");
}
